package com.demo.validator;

import com.demo.pojo.Student;
import com.demo.pojo.User;
import com.raa.core.Validator;

public class Validators {

	public enum Codes {
		NotUser,
		NotStudent,
		LoginFail
	}

	public static class IsUser implements Validator<Object> {

		@Override
		public boolean validate (Object role) {
			return role instanceof User;
		}

		@Override
		public Object errCode ( ) {
			return Codes.NotUser;
		}
	}

	public static class UsernameAndPassword implements Validator<User> {

		@Override
		public boolean validate (User role) {
			return role.getUserId().equals("20152203358") &&
					role.getPassword().equals("1498696873cary");
		}

		@Override
		public Object errCode ( ) {
			return Codes.LoginFail;
		}
	}

	public static class IsStudent implements Validator<User> {

		@Override
		public boolean validate (User role) {
			return role instanceof Student &&
					role.getUserId().startsWith("201522033");
		}

		@Override
		public Object errCode ( ) {
			return Codes.NotStudent;
		}
	}
}
